class Point {
  num x = 0;
  num y = 0;

  Point(this.x, this.y) {}
}

class ImmutablePoint {
  // 属性必须通过 final 声明
  final num x;
  final num y;

  // 常量构造函数必须通过 const 声明
  const ImmutablePoint(this.x, this.y);
}

void main(List<String> args) {
  Point p1 = new Point(1, 2);
  Point p2 = new Point(1, 2);
  print(p1 == p2);

  // 常量构造函数可以当做普通构造函数来使用
  ImmutablePoint p3 = new ImmutablePoint(2, 3);
  ImmutablePoint p4 = new ImmutablePoint(2, 3);
  print(p3 == p4);

  // 声明不可变对象必须通过const关键字
  ImmutablePoint p5 = const ImmutablePoint(2, 3);
  ImmutablePoint p6 = const ImmutablePoint(2, 3);
  print(p5 == p6);

  // 实例化时，new 关键字可以省略
  ImmutablePoint p7 = ImmutablePoint(2, 3);
  ImmutablePoint p8 = ImmutablePoint(2, 3);
  print(p7 == p8);
}
